package viewModel;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import Model.Baza;
import Model.Wlasciciel;
import Model.Wlasciciele;



public class OwnersTableModel extends AbstractTableModel{
	
	private String[] columnNames = {"ID", "Imie", "Nazwisko"};
	private Object[][] data;
		
	
	public OwnersTableModel(){
		this.setTable(Baza.getWlascicieleStatic());
	}
	public void setTable(Wlasciciele wlasciciele){
		ArrayList<Wlasciciel> list = (ArrayList<Wlasciciel>) wlasciciele.getWlasciciele();
		data = new Object[list.size()][4];
		Iterator<Wlasciciel> it = list.iterator();
		int i=0;
		while(it.hasNext()){
			
			Wlasciciel temp = it.next();
			System.out.println(temp);
			data[i][0] = temp.getWlasciciel_id();
			data[i][1] = temp.getImie();
			data[i][2] = temp.getNazwisko();
			i++;
		}
	}
	
	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return data.length;
	}
	
	public String getColumnName(int col) {
        return columnNames[col];
    }
	
	@Override
	public Object getValueAt(int row, int col) {
		return data[row][col];
	}
	
	 public Class getColumnClass(int c) {
         return getValueAt(0, c).getClass();
     }
	 
	 public void setValueAt(Object object, int row, int column){
		 data[row][column] = object;
		 this.fireTableCellUpdated(row, column);
	 }
	 
	 public boolean isCellEditable(int row, int col){
		 if(col == 0)
			 return false;
		 return true;
	 }
	
}